import {createRouter, createWebHashHistory} from 'vue-router';
import AdminIndex from '@/pages/admin/index.vue';
import About from '@/pages/about.vue';
import NotFound from '@/pages/404.vue';
import AdminLogin from '@/pages/admin/login.vue';
import Admin from '@/layouts/admin.vue'
import PublicLayout from '@/layouts/public.vue'
import AdminArticleList from '@/pages/admin/article-list.vue'
import AdminCategoryList from '@/pages/admin/category-list.vue'
import AdminTagList from '@/pages/admin/tag-list.vue'
import AdminBlogSetting from '@/pages/admin/blog-setting.vue'
import AdminAiChat from '@/pages/admin/ai-chat.vue'
import Index from '@/pages/frontend/index.vue'
import ArticleDetail from '@/pages/frontend/article-detail.vue'
import CategoryList from '@/pages/frontend/category-list.vue'
import TagList from '@/pages/frontend/tag-list.vue'
import CategoryArticleList from '@/pages/frontend/category-article-list.vue'
import TagArticleList from '@/pages/frontend/tag-article-list.vue'
import ArchiveList from '@/pages/frontend/archive-list.vue'
import NoticesList from '@/pages/frontend/notices-list.vue'
import UserDashboard from '@/pages/user/index.vue'
import UserArticleList from '@/pages/user/article-list.vue'
import UserCommentList from '@/pages/user/comment-list.vue'
import UserAiChat from '@/pages/user/ai-chat.vue'
import UserBlogSetting from '@/pages/user/blog-setting.vue'
import UserArchiveList from '@/pages/user/archive-list.vue'
import Popular from '@/pages/frontend/popular.vue'

const routes = [
    {
        // 指定访问路径
        path: '/admin',
        component: Admin,
        // 使用到 admin.vue 布局的，都需要放置在其子路由下面
        children: [{
            path: '/admin',
            component: AdminIndex,
            meta: {
                title: '仪表盘'
            }
        }, {
            path: '/admin/article/list',
            component: AdminArticleList,
            meta: {
                title: '文章管理'
            }
        }, {
            path: '/admin/category/list',
            component: AdminCategoryList,
            meta: {
                title: '分类管理'
            }
        }, {
            path: '/admin/tag/list',
            component: AdminTagList,
            meta: {
                title: '标签管理'
            }
        }, {
            path: '/admin/comment/list',
            component: () => import('@/pages/admin/comment-manage.vue'),
            meta: {
                title: '评论管理'
            }
        }, {
            path: '/admin/ai/chat',
            component: AdminAiChat,
            meta: {
                title: 'AI助手'
            }
        }, {
            path: '/admin/notice/list',
            component: () => import('@/pages/admin/notice-list.vue'),
            meta: {title: '公告管理'}
        }, {
            path: '/admin/archive/list',
            component: () => import('@/pages/admin/archive-list.vue'),
            meta: {title: '归档管理'}
        }, {
            path: '/admin/blog/setting',
            component: AdminBlogSetting,
            meta: {
                title: '博客设置'
            }
        }, {
            path: '/admin/register',
            component: () => import('@/pages/admin/register.vue'),
            meta: {
                title: '注册'
            }
        }]

    },
    {
        path: '/about',
        component: About
    },
    // 将匹配所有内容并将其放在 `$route.params.pathMatch` 下
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: NotFound
    },
    {
        path: '/login',
        component: AdminLogin,
        meta: {
            title: '登录页'
        }
    },
    // Frontend pages with public layout
    {
        path: '/',
        component: PublicLayout,
        children: [
            {
                path: '',
                component: Index,
                meta: {
                    title: 'WeBlog首页'
                }
            },
            {
                path: '/article/detail',
                component: ArticleDetail,
                meta: {
                    title: '文章详情页'
                },
            },
            {
                path: '/category',
                component: CategoryList,
                meta: {
                    title: '分类'
                },
            },
            {
                path: '/tag',
                component: TagList,
                meta: {
                    title: '标签'
                },
            },
            {
                path: '/category/list',
                component: CategoryArticleList,
                meta: {
                    title: '分类文章列表'
                },
            },
            {
                path: '/tag/list',
                component: TagArticleList,
                meta: {
                    title: '标签文章列表'
                },
            },
            {
                path: '/archive',
                component: ArchiveList,
                meta: {
                    title: '归档'
                },
            },
            {
                path: '/notices',
                component: NoticesList,
                meta: {
                    title: '公告'
                },
            },
            {
                path: '/popular',
                component: Popular,
                meta: {
                    title: '热门'
                },
            },
        ]
    },
    {
        path: '/user',
        component: () => import('@/layouts/user.vue'),
        children: [
            {
                path: '',  // 默认子路由，相当于 '/user'
                component: UserDashboard,
                meta: {
                    title: '用户仪表盘'
                }
            },
            {
                path: 'article/list',  // 完整路径为 '/user/article/list'
                component: UserArticleList,
                meta: {
                    title: '文章管理'
                }
            },
            {
                path: 'favorite',  // 完整路径为 '/user/favorite'
                component: () => import('@/pages/user/favorite/index.vue'),
                meta: {
                    title: '收藏管理'
                }
            },
            {
                path: 'comment/list',  // 完整路径为 '/user/comment/list'
                component: () => import('@/pages/user/comment-manage.vue'),
                meta: {
                    title: '评论管理'
                }
            },
            {
                path: 'ai/chat',  // 完整路径为 '/user/ai/chat'
                component: UserAiChat,
                meta: {
                    title: 'AI助手'
                }
            },
            {
                path: 'archive/list',  // 完整路径为 '/user/archive/list'
                component: UserArchiveList,
                meta: {
                    title: '归档管理'
                }
            },
            {
                path: 'blog/setting',  // 完整路径为 '/user/blog/setting'
                component: UserBlogSetting,
                meta: {
                    title: '博客设置'
                }
            }
        ]
    }

]

const router = createRouter({
    // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
    history: createWebHashHistory(),
    routes, // `routes: routes` 的缩写
})

// ES6 模块导出语句，它用于将 router 对象导出，以便其他文件可以导入和使用这个对象
export default router